home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_08 / phillip2 / mainfilt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-23  |  4.4 KB  |  155 lines

  1.  
  2.     /*********************************************
  3.     *
  4.     *   file d:\cips\mainfilt.c
  5.     *
  6.     *   Functions: This file contains
  7.     *      main
  8.     *
  9.     *   Purpose:
  10.     *      This file contains the main calling
  11.     *      routine in an image filtering program.
  12.     *
  13.     *   External Calls:
  14.     *      gin.c - get_image_name
  15.     *      tiff.c - read_tiff_header
  16.     *      filter.c - filter_image
  17.     *                 median_filter
  18.     *                 high_pixel
  19.     *                 low_pixel
  20.     *
  21.     *   Modifications:
  22.     *      15 February 1992 - created
  23.     *      01 January 1993 - added calls to
  24.     *          high_pixel and low_pixel.
  25.     *
  26.     ***********************************************/
  27.  
  28. #include "cips.h"
  29.  
  30.  
  31.  
  32. short the_image[ROWS][COLS];
  33. short out_image[ROWS][COLS];
  34.  
  35. main(argc, argv)
  36.    int argc;
  37.    char *argv[];
  38. {
  39.  
  40.    char     name[80], name2[80], low_high[80];
  41.    int      count, i, ie, il, j, le, length, ll, lw,
  42.             type, width;
  43.    short    filter[3][3];
  44.    struct   tiff_header_struct image_header;
  45.  
  46.    my_clear_text_screen();
  47.  
  48.        /*********************************************
  49.        *
  50.        *   Interpret the command line parameters.
  51.        *
  52.        **********************************************/
  53.  
  54.    if(argc < 5){
  55.     printf(
  56.     "\n\nNot enough parameters:"
  57.      "\n"
  58.      "\n usage: mainfilt in-file out-file type "
  59.      " low-or-high-pass"
  60.      "\n"
  61.      "\n   recall type: 6, 9, 10, 16, 32 for low pass"
  62.      "\n   recall type: 1, 2, 3 for high pass"
  63.      "\n   recall type: is the size of the nxn area "
  64.      "\n                for median, high pixel and"
  65.      "\n                low pixel filtering"
  66.      "\n   low-or-high-pass l=low pass h=high pass "
  67.      "\n                    m=median filter"
  68.      "\n                    i=high pixel"
  69.      "\n                    o=low pixel"
  70.      "\n");
  71.     exit(0);
  72.    }
  73.  
  74.    strcpy(name, argv[1]);
  75.    strcpy(name2, argv[2]);
  76.    type = atoi(argv[3]);
  77.    strcpy(low_high, argv[4]);
  78.  
  79.    il = 1;
  80.    ie = 1;
  81.    ll = ROWS+1;
  82.    le = COLS+1;
  83.  
  84.        /*********************************************
  85.        *
  86.        *   Read the input image header and setup
  87.        *   the looping counters.
  88.        *
  89.        *   If high or low pass filtering, setup
  90.        *   the filter mask array.
  91.        *
  92.        **********************************************/
  93.  
  94.    read_tiff_header(name, &image_header);
  95.  
  96.    length = (ROWS-10 + image_header.image_length)/ROWS;
  97.    width  = (COLS-10 + image_header.image_width)/COLS;
  98.    count  = 1;
  99.    lw     = length*width;
  100.    printf("\nlength=%d  width=%d", length, width);
  101.  
  102.    if(low_high[0] == 'l' ||
  103.       low_high[0] == 'L' ||
  104.       low_high[0] == 'h' ||
  105.       low_high[0] == 'H')
  106.          setup_filters(type, low_high, filter);
  107.  
  108.        /*********************************************
  109.        *
  110.        *   Loop over the input image and filter it
  111.        *   using either the high or low pass filters
  112.        *   using a mask OR using the median filter.
  113.        *
  114.        **********************************************/
  115.  
  116.    for(i=0; i<length; i++){
  117.       for(j=0; j<width; j++){
  118.          printf("\nrunning %d of %d", count, lw);
  119.          count++;
  120.  
  121.          if(low_high[0] == 'l' ||
  122.             low_high[0] == 'L' ||
  123.             low_high[0] == 'h' ||
  124.             low_high[0] == 'H')
  125.               filter_image(name, name2, the_image,
  126.                            out_image, il+i*ROWS,
  127.                            ie+j*COLS, ll+i*ROWS,
  128.                            le+j*COLS, filter, type);
  129.  
  130.          if(low_high[0] == 'm' ||
  131.             low_high[0] == 'M')
  132.               median_filter(name, name2, the_image,
  133.                             out_image, il+i*ROWS,
  134.                             ie+j*COLS, ll+i*ROWS,
  135.                             le+j*COLS, type);
  136.  
  137.          if(low_high[0] == 'i' ||
  138.             low_high[0] == 'H')
  139.               high_pixel(name, name2, the_image,
  140.                          out_image, il+i*ROWS,
  141.                          ie+j*COLS, ll+i*ROWS,
  142.                          le+j*COLS, type);
  143.  
  144.          if(low_high[0] == 'o' ||
  145.             low_high[0] == 'O')
  146.               low_pixel(name, name2, the_image,
  147.                         out_image, il+i*ROWS,
  148.                         ie+j*COLS, ll+i*ROWS,
  149.                         le+j*COLS, type);
  150.  
  151.  
  152.       }  /* ends loop over j */
  153.    }  /* ends loop over i */
  154. }  /* ends main  */
  155.